package com.timemanager.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.timemanager.model.Event;

/**
 * Created by He ZQ on 2016/3/25.
 * Email: Alexmocer@hotmail.com
 */
public class TimeManagerOpenHelper extends SQLiteOpenHelper {

    /**
     * Event表建表语句
     */
    public static final String CREATE_EVENT = "create table Event ("
            + "id integer primary key autoincrement, "
            + "event_type text , "
            + "event_name text unique)";
    /**
     * Event_Time表建表语句
     */
    public static final String CREATE_EVENT_TIME = "create table Event_Time ("
            + "id integer primary key autoincrement, "
            + "event_id integer, "
            + "start_datetime text not null default (datetime('now','localtime')), "
            + "elapsed_time integer)";

    public TimeManagerOpenHelper(Context context, String name,
                                 SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_EVENT);
        db.execSQL(CREATE_EVENT_TIME);
        db.execSQL("insert into Event(event_type, event_name) values ('学习', '语文')");
        db.execSQL("insert into Event(event_type, event_name) values ('学习', '数学')");
        db.execSQL("insert into Event(event_type, event_name) values ('学习', '英语')");
        db.execSQL("insert into Event(event_type, event_name) values ('工作', '开会')");
        db.execSQL("insert into Event(event_type, event_name) values ('工作', '开发')");
        db.execSQL("insert into Event(event_type, event_name) values ('工作', '设计')");
        db.execSQL("insert into Event(event_type, event_name) values ('生活', '聊天')");
        db.execSQL("insert into Event(event_type, event_name) values ('生活', '家庭聚会')");
        db.execSQL("insert into Event(event_type, event_name) values ('生活', '做家务')");
        db.execSQL("insert into Event(event_type, event_name) values ('运动', '打篮球')");
        db.execSQL("insert into Event(event_type, event_name) values ('运动', '踢足球')");
        db.execSQL("insert into Event(event_type, event_name) values ('运动', '跑步')");
        db.execSQL("insert into Event(event_type, event_name) values ('娱乐', '听音乐')");
        db.execSQL("insert into Event(event_type, event_name) values ('娱乐', '看电影')");
        db.execSQL("insert into Event(event_type, event_name) values ('娱乐', '玩游戏')");
        db.execSQL("insert into Event(event_type, event_name) values ('其他', '发呆')");
        db.execSQL("insert into Event(event_type, event_name) values ('其他', '做无聊的事浪费时间')");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
